package com.asset.dispoal.dataDetail.service.commom;

import com.asset.dispoal.dataDetail.domain.db.mapper.SysDataDetailMapper;
import com.asset.dispoal.dataDetail.dto.SysDataTypeSaveRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.core.util.StringUtil;
import tech.mhuang.pacebox.springboot.protocol.Result;

@Component
public class SysDataTypeSaveCommand implements BaseCommand<SysDataTypeSaveRequest, Result> {

    @Autowired
    private SysDataDetailMapper dataDetailMapper;

    @Autowired
    private BaseIdeable<String> ideable;


    public Result execute(SysDataTypeSaveRequest request) {
        if (StringUtil.isNotBlank(request.getId())) {
            dataDetailMapper.deleteType(request.getId());
        }
        request.setId(ideable.generateId());
        dataDetailMapper.insertType(request);
        return Result.ok();
    }
}
